<template>
  <div class="common">
    <div
      class="common-item"
      v-for="(item, index) in dataList"
      :key="index"
      @click="detail(item.id)"
    >
      <el-image :src="item.cover" class="item-img"></el-image>
      <div class="item-bg">
        <span>{{ item.courseName || item.bookName }}</span>
        <span>{{ item.courseCategory }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { updateClickCount } from "@/api/client/courseVideo";
export default {
  name: "CommonItemView",
  props: {
    dataList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    // 跳转到详情页
    async detail(id) {
      const res = this.$route.fullPath;
      if (res.includes("courseVideo")) {
        await this.updateClickCount(id);
      }
      this.$router.push({
        path: `${res}/detail/${id}`,
      });
    },
    // 视频点击量+1
    async updateClickCount(id) {
      await updateClickCount(id);
    },
  },
};
</script>

<style lang="less" scoped>
.common {
  display: flex;
  flex-wrap: wrap;
  padding: 10px 40px;
  .common-item {
    position: relative;
    width: 240px;
    height: 220px;
    margin-left: 20px;
    cursor: pointer;
    .item-bg {
      position: absolute;
      left: 50%;
      transform: translate(-50%);
      bottom: 20px;
      width: 220px;
      height: 60px;
      background-color: rgba(240, 240, 240, 0.2);
      border-radius: 20px;
      box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
      transition: 0.5s;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      span:nth-of-type(1) {
        margin-top: 20px;
      }
      span {
        font-size: 12px;
        transition: 0.5s;
      }
    }
    .item-img {
      position: absolute;
      left: 50%;
      bottom: 50px;
      transform: translate(-50%);
      width: 90px;
      height: 90px;
      z-index: 8;
      box-shadow: 0 10px 12px rgba(0, 0, 0, 0.25);
      transition: 0.5s;
    }
    &:hover {
      .item-bg {
        width: 240px;
        height: 80px;
        span {
          font-size: 16px;
        }
      }
      .item-img {
        bottom: 80px;
        width: 110px;
        height: 130px;
      }
    }
  }
}
</style>